package com.primeton.common.connection.impl.synchronization;

import com.eos.infra.connection.IStatementSynchronization;
import com.eos.runtime.core.TraceLoggerFactory;
import com.eos.system.logging.Logger;
import com.eos.system.utility.StringUtil;

import java.sql.Statement;

public class TraceLoggerStatementSynchronization implements IStatementSynchronization {
	private static Logger log = TraceLoggerFactory.getLogger(TraceLoggerStatementSynchronization.class);

	public void beforeSqlExecute(Statement statement, String sql) {
		System.out.println("SQL===>" + sql.trim().replaceAll("[\\t\\n\\r]", ""));
		if (log.isDebugEnabled()) {
			log.debug(StringUtil.concat(new Object[] { "Sql[", sql, "] execute begin." }));
		}
	}

	public void afterSqlExecute(Statement statement, String sql) {
		if (log.isDebugEnabled()) {
			log.debug(StringUtil.concat(new Object[] { "Sql[", sql, "] execute end." }));
		}
	}

	public void afterSqlExecuteWithException(Statement statement, String sql, Exception exception) {
		if (log.isErrorEnabled()) {
			log.error(StringUtil.concat(new Object[] { "Sql[", sql, "] execute error." }), exception);
		}
	}

	public void onCreate(Statement statement) {
	}

	public void onClose(Statement statement) {
	}

	public void onException(Statement statement, Exception exception) {
	}
}
